package com.eastcom.collection.provider


import com.eastcom.collection.tools.*
import com.eastcom.collection.tools.db.DbEngine
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.eastcom.collection.context.*
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;




public class DbContextProvider{
	private static Log logger = LogFactory.getLog(DbContextProvider.class);
	public boolean loadDbSource(String dbName,String tbName){
		DbEngine dbEngine = (DbEngine) SpringContextProvider.getBean("dbEngine");
		ServerContext.setCustomerType(dbName);
		boolean result = dbEngine.getTableInfo(dbName, tbName);
		return result;
	}
	
	public boolean loadDbSource(String dbName,String tbName, boolean isDomain){
		DbEngine dbEngine = (DbEngine) SpringContextProvider.getBean("dbEngine");
		if(isDomain){
			dbEngine.getJdbcUtil().setDataSource(DynamicBeanDomianProvider.getBean(dbName))
		}else{
			dbEngine.getJdbcUtil().setDataSource(SpringContextProvider.getBean(dbName))
		}
		boolean result = dbEngine.getTableInfo(dbName, tbName);
		return result;
	}

	public boolean loadExternDbSource(String dbName,String tbName){
		DbEngine dbEngine = (DbEngine) SpringContextProvider.getBean("dbEngine");
		javax.sql.DataSource dataSource = DynamicBeanDomianProvider.getBean(dbName)
		dbEngine.jdbcUtil.setDataSource(dataSource)
		boolean result = dbEngine.getTableInfo(dbName, tbName);
		return result;
	}
}
